//
//  PolicyMessageViewController.m
//  ChatForHot
//
//  Created by FLY on 2018/10/10.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "PolicyMessageViewController.h"

@interface PolicyMessageViewController ()

@end

@implementation PolicyMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = NSLocalizedString(@"StrN020", nil);
}
- (void)HOTCHATInsertSubViews{
    
    [self.view addSubview:self.HOTCHATmsgText];
    [self.HOTCHATmsgText mas_updateConstraints:^(MASConstraintMaker *make) {

        make.left.top.equalTo(self.view).offset(15);
        make.right.bottom.equalTo(self.view).offset(-15);
    }];
    
    [self HOTCHATgetTheTextInfo];
}
- (void)HOTCHATgetTheTextInfo{
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Policy-English" ofType:@"txt"];
    NSString *textStr = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

    if (textStr.length > 0) {
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textStr];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 6;
        NSDictionary *attrsDictionary1 = @{NSFontAttributeName:[UIFont systemFontOfSize:14],
                                           NSParagraphStyleAttributeName:paragraphStyle,
                                           NSForegroundColorAttributeName:HOTCHATrgb(26, 26, 26)};
        
        
        
        [attributedString addAttributes:attrsDictionary1 range:NSMakeRange(0, textStr.length)];
        
        
        
        NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle2.lineSpacing = 4;
        NSDictionary *attrsDictionary2 = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],
                                           NSParagraphStyleAttributeName:paragraphStyle2,
                                           NSForegroundColorAttributeName:[UIColor blackColor]};
        
        for (NSString *msg in self.HOTCHATdataArr) {
            NSRange range = [textStr rangeOfString:msg];
            
            if (range.location != NSNotFound) {
                [attributedString addAttributes:attrsDictionary2 range:NSMakeRange(range.location, range.length)];
            }
            
        }
        self.HOTCHATmsgText.attributedText = attributedString;
    }
}
- (UITextView *)HOTCHATmsgText{
    if (_HOTCHATmsgText == nil) {
        _HOTCHATmsgText = [[UITextView alloc] init];
        _HOTCHATmsgText.editable = NO;
        _HOTCHATmsgText.selectable = NO;
        if (@available(iOS 11.0, *)) {
            _HOTCHATmsgText.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
        } else {
            // Fallback on earlier versions
        }
    }
    return _HOTCHATmsgText;
}

- (NSMutableArray *)HOTCHATdataArr{
    if (_HOTCHATdataArr == nil) {
        _HOTCHATdataArr = [[NSMutableArray alloc] init];
        
        [_HOTCHATdataArr addObject:@"Information Collection and Use"];
        [_HOTCHATdataArr addObject:@"Security  "];
        [_HOTCHATdataArr addObject:@"Third Party Service Providers"];
        [_HOTCHATdataArr addObject:@"Supplementation of Information"];
        [_HOTCHATdataArr addObject:@"Contests/Surveys"];
        [_HOTCHATdataArr addObject:@"Targeted Advertisements"];
        [_HOTCHATdataArr addObject:@"UpONENIGHT Your Information "];
        [_HOTCHATdataArr addObject:@"Compliance with Laws and Law Enforcement"];
        [_HOTCHATdataArr addObject:@"Changes in Our Practices"];
    }
    return _HOTCHATdataArr;
}


@end
